package cn.org.rookie.jeesdp.web.utils;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.util.Map;

public abstract class RequestUtils {

    /**
     * 获取当前request
     *
     * @return 当前request
     */

    public static HttpServletRequest getRequest() {
        return getRequestAttributes().getRequest();
    }


    /**
     * 获取当前RequestAttributes
     *
     * @return 当前RequestAttributes
     */

    public static ServletRequestAttributes getRequestAttributes() {
        return (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
    }


    /**
     * 获取当前Request的ParameterMap
     *
     * @return 获取当前Request的ParameterMap
     */

    public static Map<String, String[]> getParameterMap() {
        return getRequest().getParameterMap();
    }


    /**
     * 通过key获取当前Request的Parameter
     *
     * @param key 参数
     * @return key对应的Parameter
     */

    public static String getParameter(String key) {
        return getRequest().getParameter(key);
    }


    /**
     * 通过key获取当前Request的Parameter数组
     *
     * @param key 参数
     * @return key对应的Parameter数组
     */

    public static String[] getParameterValues(String key) {
        return getRequest().getParameterValues(key);
    }

}
